package mz.behaveas.runner {	/**	 * First implementation, prove of concept.	 * 	 * @deprecated
	 * @author maxim.zaks@gmail.com
	 */
	public class PrimitiveRunner {
		private static var catched : Boolean;
		private static var malformed : int;
		private static var expected : int;
		private static var unexpected : int;
		public static function checkSpecifications(... specs : *) : void {
			for each (var spec : * in specs) {
				trace(spec.description);
				var expectations : Array = spec.expectations as Array;
				trace("This spec has " + expectations.length + " expectations");
				trace("-------------------");
				var expectationIndex : int = 0;
				for each (var expectation : * in expectations) {
					expectationIndex++;
					var exp : ExpectationOld = new ExpectationOld(expectation);
					trace("Expectation " + expectationIndex + ":");
					trace("   " + exp.descritionText);
					if(!exp.hasBehaviour) {
						continue;
					}
					if(exp.hasThrowValue && exp.hasEqualValue || exp.hasThrowValue && exp.hasNotEqualValue) {
						trace("    [MALFORMED] Expectation is malformed because you neiver expect a value or an error.");
						malformed++;
					}
					try {
						var value : * = exp.behave;
						if(exp.hasEqualValue && value == expectation.shouldEqual) {
							trace("   [AS EXPECTED] behaviour returned " + value);
							expected++;
						} else if(exp.hasNotEqualValue && value != expectation.shouldNotEqual) {
							trace("   [AS EXPECTED] behaviour returned value '" + value + "' not equal to " + expectation.shouldNotEqual);
							expected++;
						} else {
							trace("   [NOT AS EXPECTED] we expected " + expectation.shouldEqual + " but behaviour returned " + value);
							unexpected++;
						}
					}catch(e : Error) {
						catched = true;
						if(exp.hasThrowValue && e is expectation.shouldThrow) {
							trace("   [AS EXPECTED] behaviour was enterupted by " + e.getStackTrace());
							expected++;
						} else {
							trace("   [NOT AS EXPECTED] behaviour was enterupted by " + e.getStackTrace());
							unexpected++;
						}
					} finally {
						if(!catched && exp.hasThrowValue) {
							trace("   [NOT AS EXPECTED] behaviour was not enterupted by " + expectation.shouldThrow);
						}
					}
				}
				trace("From " + expectations.length + " expectations " + expected + " went as expected and " + unexpected + " went unexpected.");
				if(malformed > 0) {
					trace(malformed + " expectations are malformed");
				}
				trace();
			}
		}
	}
}
class ExpectationOld {	private var _hasBehaviour : Boolean;	private var _hasEqualValue : Boolean;	private var _hasNotEqualValue : Boolean;	private var _hasThrowValue : Boolean;	private var _descritionText : String;	private var _behave : Function;	public function ExpectationOld(expectation : *) {		for (var memberName : String in expectation) {			if(memberName == "behaviour") {				_hasBehaviour = true;				_behave = expectation[memberName];			}			if(memberName == "shouldEqual") {				_hasEqualValue = true;			}			if(memberName == "shouldNotEqual") {				_hasNotEqualValue = true;			}			if(memberName == "shouldThrow") {				_hasThrowValue = true;			}			if(memberName == "description") {				_descritionText = expectation["description"];			}		}	}	public function get hasBehaviour() : Boolean {		return _hasBehaviour;	}	public function get hasEqualValue() : Boolean {		return _hasEqualValue;	}	public function get hasNotEqualValue() : Boolean {		return _hasNotEqualValue;	}	public function get hasThrowValue() : Boolean {		return _hasThrowValue;	}	public function get descritionText() : String {		return _descritionText;	}	public function get behave() : * {		return _behave();	}}